package com.acme;

import java.util.List;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Gender;
import com.acme.bankapp.service.bank.BankService;


public class BankApplication {
	
	/**
	 * Random modifier for Bank object
	 * @param bank Bank
	 */
	private static void modifyBank(Bank bank){
		List<Client> clients; 
		int i = 0;
		clients = bank.getClients();
		for (Client client: clients){ // iterate all clients and change them
			i++; //iterator
			if (i % 3 == 0){
				client.withdraw(i * 10);
			}else{
				client.deposit(i*5);
			}
		}
	}
	
	/**
	 * Prints balances of all clients
	 * @param bank Bank
	 */
	private static void printBalance(Bank bank){
		List<Client> clients; //List of Clients (we can get them from Bank)
		clients = bank.getClients(); // Get clients of bank 
		for (Client client: clients){
			System.out.println(client.getClientSalutation() + ": "+ client.getBalance()); // Just print balance of current Client
		}
	}
	
	public static void main(String[] args){
		Bank bank = Bank.getInstance(); // I'm not sure, that we need Singleton. How many banks do we have?
		BankService bankService = new BankService(); // New instance for bank modificator
		for (int i = 0; i < 10; i++){ // let's create some instances of Client
			if (i % 2 == 0){
				bankService.addClient(bank, new Client("Ivanov"+i, "Ivan", Gender.MALE, i*10)); // BankService adds clients (Clients is a List) without overdraft
			}else{
				bankService.addClient(bank, new Client("Petrova"+i, "Nadja", Gender.FEMALE, i*10, i*5)); // BankService adds clients (Clients is a List) with overdraft
			}
		}
		printBalance(bank); // Print Balance before modification
		modifyBank(bank); // Modify balance
		printBalance(bank); //Print Balance after modification
		bankService.printMaximumAmountToWithdraw(bank); // Print maximumAmountToWithdraw for each Client 
	}
}
